package cn.stronglink.asset.module.visitor.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.toolkit.IdWorker;

import cn.stronglink.asset.model.VisitorRegistration;
import cn.stronglink.asset.module.visitor.mapper.VisitorMapper;
import cn.stronglink.suite.core.util.WebUtil;

@Service
@Transactional(rollbackFor=Exception.class)
public class VisitorService {
	
	@Autowired
	private VisitorMapper visitorMapper;
	
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public Page<VisitorRegistration> getVisitorByParams(Page<VisitorRegistration> page, Map<String, Object> param){	
		List<VisitorRegistration> list = visitorMapper.getVisitorByParams(page, param);
		page.setRecords(list);
		return page;
	}

	public void create(VisitorRegistration vr) {
		Date date=new Date();
		vr.setId(IdWorker.getId());
		vr.setCreateBy(WebUtil.getCurrentUser());
		vr.setCreateTime(date);
		visitorMapper.create(vr);
	}

	public void entry(VisitorRegistration vr) {
		Date date=new Date();
		vr.setUpdateBy(WebUtil.getCurrentUser());
		vr.setUpdateTime(date);
		visitorMapper.entry(vr);
	}

	public void leave(VisitorRegistration vr) {
		Date date=new Date();
		vr.setUpdateBy(WebUtil.getCurrentUser());
		vr.setUpdateTime(date);
		visitorMapper.leave(vr);
	}

}
